home *** CD-ROM | disk | FTP | other *** search
- /*//////////////////////////////////////////////////////////////////////
- filename: ar_index.js
- copyright(c): 2002, 2003 Tiny Software Inc (http://www.tinysoftware.com)
- author: Martin Navratil (mnavratil@tinysoftware.com)
- product: Tiny Personal Firewall 5.x
- description: javascript code used in ar_index.html
- ///////////////////////////////////////////////////////////////////////*/
-
- // ar_index.js
- var label;
- var isNew = 0;
- var bIsDll;
- var LT_CHECKSUM = 0,
- LT_PATH = 1,
- LT_NAME = 2,
- LT_CHECKSUM_AND_PATH = 3,
- LT_CHECKSUM_AND_NAME = 4,
- AR_ALLOW = 1,
- AR_PREVENT = 0,
- AR_ASKUSER = 2,
- AL_IGNORE = 0,
- AL_MONITOR = 1,
- AL_ALERT = 2;
-
- var ERR_LABEL_EXISTS="Label already exists - will not be saved.",
- TXT_MSG1 = "Label will be enrolled into ",
- TXT_MSG2 = " database",
- TXT_MSG3 = " since ",
- TXT_MSG4 = " is a ",
- TXT_MSG5 = " group.",
- TXT_USER = "user",
- TXT_MASTER = "master";
-
- var bGroupIsServer = 0, bGroupIsClient = 0;
- var curGr = null, arrGroupSelect;
-
- function OnLoad()
- {
- if (iContext == 0 && iManaged == 0)
- Users.innerHTML = '<img src="ico-usr.gif" width="33" height="28" border="0" alt="" align="absmiddle">' + GetUsersHtml();
- ARXWaitForCreate();
- }
- function Refresh()
- {
- location.reload();
- }
- function ARXWaitForCreate()
- {
- if (CfgARX.controlWindow == 0)
- setTimeout("ARXWaitForCreate()", 30);
- else
- FinishARXInit();
- }
- function FinishARXInit()
- {
- var div = document.all["div_warning"];
- if (iContext)
- {
- div.className = "expanded";
- }
- CfgARX.bgColor = "#E7EFF7";
- if (ClientAppParser == null)
- ClientAppParser = new ActiveXObject('XMLSecDB.APPParser.1');
- CfgARX.Init(ClientAppParser, ServerAppParser, iManaged, iContext);
- var RegRoot = "";
- if (!iContext)
- window.external.RegistryRoot;
- CfgARX.IsAdmin = bIsAdmin;
- CfgARX.SetRegistryRoot(RegRoot);
- divMain.className="expanded";
- }
- function WaitForCreate()
- {
- if (form.EditChks.controlWindow == 0)
- setTimeout("WaitForCreate()", 30);
- else
- FinishEditInit();
- }
- function Edit()
- {
- label = CfgARX.CurrentLabel;
- bIsDll = CfgARX.isLabelDll;
- if (label==null)
- alert("No application is selected");
- else
- {
- var clLabelList = null;
- if (ClientAppParser != null)
- clLabelList = bIsDll ? ClientAppParser.DllLabelList : ClientAppParser.LabelList;
- if (iManaged || !bIsAdmin)
- {
- try
- {
- // label can be edited only in client database
- clLabelList.Get(label.LabelID);
- form.save.disabled = false;
- form.savenew.disabled = false;
- }
- catch(e)
- {
- if (!iManaged && !bIsAdmin || iManaged && !iContext)
- {
- form.save.disabled = true;
- form.savenew.disabled = true;
- }
- }
- }
- divMain.className="collapsed";
- divEdit.className="expanded";
- div_edit_warning.className="expanded";
- divChecksum.className="expanded";
- DivParserSelect.className="collapsed";
- isNew = 0;
- WaitForCreate();
- }
- }
- function Enroll(bDll)
- {
- if (bDll || bDll == 0)
- bIsDll = bDll;
- else
- bIsDll = CfgARX.isLabelDll;
- try
- {
- label = bIsDll ? ClientAppParser.DllLabelList.CreateDllLabel() : ClientAppParser.LabelList.CreateLabel();
- } catch (e)
- {
- try
- {
- label = bIsDll ? ServerAppParser.DllLabelList.CreateDllLabel() : ServerAppParser.LabelList.CreateLabel();
- } catch (e)
- {
- alert("Failed to create a new label");
- return;
- }
- }
- divMain.className="collapsed";
- divEdit.className="expanded";
- div_edit_warning.className="expanded";
- divChecksum.className="expanded";
- isNew = 1;
- var srGroups = null, clGroups = null;
- if (ServerAppParser != null && !(iManaged && !iContext))
- srGroups = bIsDll ? ServerAppParser.DllGroupList : ServerAppParser.AppGroupList;
- if (ClientAppParser != null )
- clGroups = bIsDll ? ClientAppParser.DllGroupList : ClientAppParser.AppGroupList;
- GetLabelIsServerOrClient(srGroups, clGroups);
- var collSrGroups = null, collClGroups = null;
- if (srGroups != null && !(iManaged && !iContext))
- collSrGroups = new Enumerator(srGroups);
- if (clGroups != null && !iContext)
- collClGroups = new Enumerator(clGroups);
- DivParserSelect.innerHTML = GetParserSelectCombo();
- DivGroupSelect.innerHTML = GetGroupSelect( collSrGroups, collClGroups );
- DivParserSelect.className="expanded";
- WaitForCreate();
- }
- function InitGroupSelectCombo()
- {
- if (ServerAppParser != null && !(iManaged && !iContext))
- srGroups = bIsDll ? ServerAppParser.DllGroupList : ServerAppParser.AppGroupList;
- if (ClientAppParser != null )
- clGroups = bIsDll ? ClientAppParser.DllGroupList : ClientAppParser.AppGroupList;
- if (srGroups != null && !(iManaged && !iContext))
- collSrGroups = new Enumerator(srGroups);
- if (clGroups != null && !iContext)
- collClGroups = new Enumerator(clGroups);
- DivGroupSelect.innerHTML = GetGroupSelect( collSrGroups, collClGroups );
- }
- function FinishEditInit()
- {
- // determine if app or dll
- form.rad_typeapp[0].checked = !bIsDll;
- form.rad_typeapp[1].checked = bIsDll;
- form.EditChks.SetLabel(label);
- form.EditChks.isDll = bIsDll;
- if (bIsDll)
- form.EditChks.FileMask = "";
- else
- form.EditChks.FileMask = "*.exe";
- form.Name.value=label.LabelID;
- form.Description.value=label.Description;
- form.Path.value = label.Path;
- form.Filename.value = label.Path;
- LoadType();
- LoadICType();
- SetIDEnable();
- }
- function Browse()
- {
- divMain.className="expanded";
- divEdit.className="collapsed";
- div_edit_warning.className="collapsed";
- CfgARX.Refresh();
- }
- function SetIDEnable()
- {
- // if (isNew)
- form.Name.disabled = false;
- // else
- // form.Name.disabled = true;
- }
- function New(bDll)
- {
- var labellist;
- if (bDll || bDll == 0)
- bIsDll = bDll;
- if (ClientAppParser != null)
- {
- labellist = bIsDll ? ClientAppParser.DllLabelList : ClientAppParser.LabelList;
- }else
- {
- labellist = bIsDll ? ServerAppParser.DllLabelList : ServerAppParser.LabelList;
- }
- label = bIsDll ? labellist.CreateDllLabel() : labellist.CreateLabel();
- form.EditChks.SetLabel(label);
- form.Name.value = "";
- form.Description.value = "";
- form.Type.value = 0;
- form.Path.value = "";
- // determine if app or dll
- form.rad_typeapp[0].checked = !bIsDll;
- form.rad_typeapp[1].checked = bIsDll;
- ChangeType();
- isNew = 1;
- SetIDEnable();
- var srGroups, clGroups;
- if (ServerAppParser != null)
- srGroups = bIsDll ? ServerAppParser.DllGroupList : ServerAppParser.AppGroupList;
- if (ClientAppParser != null)
- clGroups = bIsDll ? ClientAppParser.DllGroupList : ClientAppParser.AppGroupList;
- curGr = null;
- var collSrGroups = null, collClGroups = null;
- if (srGroups != null)
- collSrGroups = new Enumerator(srGroups);
- if (clGroups != null)
- collClGroups = new Enumerator(clGroups);
- GetLabelIsServerOrClient(srGroups, clGroups);
- DivParserSelect.innerHtml = GetParserSelectCombo();
- DivParserSelect.className="expanded";
- DivGroupSelect.innerHTML = GetGroupSelect(collSrGroups, collClGroups);
- }
-
- function GetLabelIsServerOrClient(srGroups, clGroups)
- {
- if (iContext)
- {
- bGroupIsClient = 0;
- bGroupIsServer = 1;
- }
-
- var curGrLabel = CfgARX.curGroup;
- bGroupIsClient = 0;
- bGroupIsMaster = 0;
- var curLList = null;
- try
- {
- curLList = CfgARX.CurrentLList;
- }
- catch (e)
- {
- }
- if (!bIsAdmin)
- {
- bGroupIsClient = 1;
- bGroupIsMaster = 0;
- }
- else
- if (curLList == ClientAppParser.LabelList)
- bGroupIsClient = 1;
- if (curLList == ServerAppParser.LabelList)
- bGroupIsServer = 1;
- /* {
- try {
- if (srGroups != null)
- if ((curGr = srGroups.Get(curGrLabel)) != null)
- bGroupIsServer = 1;
- } catch(e) {}
- try {
- if (clGroups != null)
- if ((curGr = clGroups.Get(curGrLabel)) != null)
- bGroupIsClient = 1;
- } catch(e) {}
- }
- */
- }
-
- function GetGroupSelect(srGroups, clGroups)
- {
- var iClient_Master;
- try {
- iClient_Master = parseInt(form.ParserSelect.selectedIndex);
- } catch(e)
- {
- // if element form.ParserSelect does not continue, we end up here
- if (iManaged)
- iClient_Master = iContext ? 0 : 1;
- else
- iClient_Master = bGroupIsClient;
- }
- // app.group selection
- var strout = '<P>Assign to application group: <SELECT id="GroupSelChange" ' +
- 'OnChange="OnGroupChange(this.value, GroupSelChange.selectedIndex);"><OPTION><None></OPTION>';
- arrGroupSelect = new Array();
- arrGroupSelect[0] = 0;
- var arrLabelTypes = new Array();
- var strGroupSelected = CfgARX.curGroup;
- if (srGroups != null && iClient_Master == 0)
- strout += AddAllGroups(srGroups, arrLabelTypes, strGroupSelected);
- while (arrGroupSelect.length - 1 < arrLabelTypes.length)
- arrGroupSelect[arrGroupSelect.length] = 1;
- if (clGroups != null && iClient_Master == 1)
- strout += AddAllGroups(clGroups, arrLabelTypes, strGroupSelected);
- while (arrGroupSelect.length - 1 < arrLabelTypes.length)
- arrGroupSelect[arrGroupSelect.length] = 2;
- strout += '</SELECT></P>';
- return strout;
- }
-
- function GetParserSelectCombo()
- {
- var strout = "";
- var curGrLabel = "";
- if (curGr != null)
- curGrLabel = bIsDll ? curGr.DllGroupID : curGr.AppGroupID;
-
- // master or client parser selection
- if (ServerAppParser == null || ClientAppParser == null || iManaged || (!bIsAdmin || bGroupIsServer != bGroupIsClient))
- {
- strout += TXT_MSG1;
- if (ClientAppParser == null || bIsAdmin && bGroupIsServer)
- strout += TXT_MASTER;
- else
- strout += TXT_USER;
- strout += TXT_MSG2;
- if (curGrLabel != "")
- {
- strout += TXT_MSG3 + curGrLabel + TXT_MSG4;
- if (bIsAdmin && bGroupIsServer)
- strout += TXT_MASTER;
- else
- strout += TXT_USER;
- strout += TXT_MSG5;
- }
- } else
- {
- strout += 'Enroll this application into <SELECT id=ParserSelect onchange="OnParserSelectChange();">' +
- '<OPTION>common</OPTION>' +
- '<OPTION selected>user</OPTION>' +
- '</SELECT>database';
- }
- return strout;
- }
- function Remove()
- {
- label = CfgARX.CurrentLabel;
- if (label==null)
- alert("No application is selected");
- else
- {
- CfgARX.Remove(-1);
- }
- }
- function OnParserSelectChange()
- {
- switch (parseInt(form.ParserSelect.selectedIndex))
- {
- case 0:
- label = bIsDll ? ServerAppParser.DllLabelList.CreateDllLabel() : ServerAppParser.LabelList.CreateLabel();
- break;
- case 1:
- label = bIsDll ? ClientAppParser.DllLabelList.CreateDllLabel() : ClientAppParser.LabelList.CreateLabel();
- break;
- }
- form.EditChks.SetLabel(label);
- InitGroupSelectCombo();
- }
- function OnGroupChange(value, index)
- {
- var srAppGrList = null, clAppGrList = null;
- if (ServerAppParser != null)
- srAppGrList = bIsDll ? ServerAppParser.DllGroupList : ServerAppParser.AppGroupList;
- if (ClientAppParser != null)
- clAppGrList = bIsDll ? ClientAppParser.DllGroupList : ClientAppParser.AppGroupList;
- if (value == "")
- {
- curGr = null;
- bGroupIsServer = 0;
- bGroupIsClient = 0;
- }
- else
- {
- switch (arrGroupSelect[index])
- {
- case 1:
- bGroupIsServer = 1;
- bGroupIsClient = 0;
- curGr = srAppGrList.Get(value);
- break;
- case 2:
- bGroupIsServer = 0;
- bGroupIsClient = 1;
- curGr = clAppGrList.Get(value);
- break;
- default:
- bGroupIsServer = 0;
- bGroupIsClient = 0;
- curGr = null;
- }
- }
- DivParserSelect.innerHTML = GetParserSelectCombo();
- }
- function reloadPathBrowser()
- {
- form.PathBrowse.outerHTML = '<INPUT id=PathBrowse value="" name=PathBrowse type=file onchange="Path.value=this.value;reloadPathBrowser();" STYLE="DISPLAY: none"></INPUT>';
- }
-
- function Apply()
- {
- if (form.Name.value == "" || form.Name.value == null)
- {
- alert("Application name must be specified");
- return 0;
- }
- var iClient_Master;
- try {
- iClient_Master = parseInt(form.ParserSelect.selectedIndex);
- } catch(e)
- {
- // if element form.ParserSelect does not continue, we end up here
- if (iManaged)
- iClient_Master = iContext ? 0 : 1;
- else
- iClient_Master = bGroupIsClient;
- }
- var labellist, grouplist = null;
- switch (iClient_Master)
- {
- case 0:
- labellist = bIsDll ? ServerAppParser.DllLabelList : ServerAppParser.LabelList;
- if (bIsAdmin)
- grouplist = bIsDll ? ServerAppParser.DllGroupList : ServerAppParser.AppGroupList;
- break;
- case 1:
- labellist = bIsDll ? ClientAppParser.DllLabelList : ClientAppParser.LabelList;
- grouplist = bIsDll ? ClientAppParser.DllGroupList : ClientAppParser.AppGroupList;
- break;
- }
-
- try
- {
- if (label.LabelID != form.Name.value)
- label.LabelID = form.Name.value;
- if (isNew == 1)
- {
- labellist.Insert(label);
- }
- } catch(e)
- {
- alert(ERR_LABEL_EXISTS);
- return 0;
- }
- label.Description = form.Description.value;
-
- var type = valueOfRadio(form.Type, 5);
-
- var ICtype = valueOfRadio(form.ICtype, 4);
- if ((label.Type == LT_CHECKSUM_AND_NAME || label.Type == LT_CHECKSUM_AND_PATH) &&
- (type != LT_CHECKSUM_AND_NAME && type != LT_CHECKSUM_AND_PATH))
- SetICType(label, 0);
-
- label.Type = type;
- if (type == LT_CHECKSUM || type == LT_CHECKSUM_AND_NAME || type == LT_CHECKSUM_AND_PATH)
- {
- form.EditChks.Apply();
- if (type != LT_CHECKSUM)
- {
- SetICType(label, ICtype);
- }
- }
-
- if (type == LT_NAME || type == LT_CHECKSUM_AND_NAME)
- label.Path = form.Filename.value;
- else
- label.Path = form.Path.value;
-
- // insert label into app group
- if (curGr != null)
- {
- var newLabelItem = bIsDll ? curGr.DllLabelList.CreateItem() : curGr.LabelList.CreateItem();
- newLabelItem.Content = label.LabelID;
- if (bIsDll)
- curGr.DllLabelList.Insert(newLabelItem);
- else
- curGr.LabelList.Insert(newLabelItem);
- }
- isNew = 0;
- SetIDEnable();
- return 1;
- }
- function valueOfRadio(r, n)
- {
- for (i = 0; i < n; i++) if (r[i].checked==true)
- return parseInt(r[i].value);
- return 0;
- }
-
- function LoadType()
- {
- var type = label.Type;
- form.Type[type].checked = true;
- ChangeType();
- }
-
- function ChangeType()
- {
- switch (valueOfRadio(form.Type, 5))
- {
- case 0:
- divPath.className="collapsed";
- divFilename.className="collapsed";
- divChecksum.className="expanded";
- form.ICtype.value = 0;
- SetICType(0);
- SetDisabled(form.ICtype, true, 4);
- break;
- case 1:
- divPath.className="expanded";
- divFilename.className="collapsed";
- divChecksum.className="collapsed";
- form.ICtype.value = 0;
- SetDisabled(form.ICtype, true, 4);
- break;
- case 2:
- divPath.className="collapsed";
- divFilename.className="expanded";
- divChecksum.className="collapsed";
- form.ICtype.value = 0;
- SetDisabled(form.ICtype, true, 4);
- break;
- case 3:
- divPath.className="expanded";
- divFilename.className="collapsed";
- divChecksum.className="expanded";
- SetDisabled(form.ICtype, false, 4);
- break;
- case 4:
- divPath.className="collapsed";
- divFilename.className="expanded";
- divChecksum.className="expanded";
- SetDisabled(form.ICtype, false, 4);
- break;
- default:
- alert("Unknown type:");
- alert(valueOfRadio(Type, 4));
- }
- }
-
- function LoadICType()
- {
- var type = label.Type;
- form.Type[type].checked = true;
- ChangeType();
- }
-
- function SetICType(labelTo, ICtype)
- {
- switch (ICtype)
- {
- case 0:
- labelTo.BGAccessResult = AR_ALLOW;
- labelTo.BGAuditLevel = AL_IGNORE;
- break;
- case 1:
- labelTo.BGAccessResult = AR_ALLOW;
- labelTo.BGAuditLevel = AL_MONITOR;
- break;
- case 2:
- labelTo.BGAccessResult = AR_ASKUSER;
- labelTo.BGAuditLevel = AL_MONITOR;
- break;
- case 3:
- labelTo.BGAccessResult = AR_PREVENT;
- labelTo.BGAuditLevel = AL_MONITOR;
- break;
- }
- }
- function SetDisabled(what, value, nofields)
- {
- for (i = 0; i < nofields; i++)
- what[i].disabled = value;
- }
-
- function LoadICType()
- {
- var ar = label.BGAccessResult, al = label.BGAuditLevel;
- var icType = 0;
- if (ar == AR_ALLOW && al == AL_IGNORE)
- icType = 0;
- else if (ar == AR_ALLOW && al == AL_MONITOR)
- icType = 1;
- else if (ar == AR_ASKUSER && al == AL_MONITOR)
- icType = 2;
- else if (ar == AR_PREVENT && al == AL_MONITOR)
- icType = 3;
- form.ICtype[icType].checked = true;
- }
-
-